﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Animation;
using Microsoft.Xna.Framework.Content;
using AI;

namespace MapLibrary.DataLoading
{
    public class SpriteData
    {
        public static string SpriteTypeFile = "./Animation/SpriteTypes/";

        public Vector2 Position { get; set; }
        public float Rotation { get; set; }
        public Vector2 Scale { get; set; }
        public bool Collidable { get; set; }
        public string SpriteTypeName { get; set; }

        [ContentSerializerIgnore]
        public SpriteType SpriteType { get; set; }
        [ContentSerializerIgnore]
        public Bot Bot { get; set; }
    }

    public class SpriteDataTypeReader : ContentTypeReader<SpriteData>
    {

        protected override SpriteData Read(ContentReader input, SpriteData existingInstance)
        {
            SpriteData newData = new SpriteData();

            newData.Position = input.ReadVector2();
            newData.Rotation = input.ReadSingle();
            newData.Scale = input.ReadVector2();
            newData.Collidable = input.ReadBoolean();
            newData.SpriteTypeName = input.ReadString();

            newData.SpriteType = input.ContentManager.Load<SpriteType>(
                SpriteData.SpriteTypeFile + newData.SpriteTypeName);
            newData.Bot = BotFactory.CreateBot(newData.SpriteType.BotName);

            return newData;
        }
    }
}
